use reqwest::blocking::Client;
use serde::Deserialize;

// 静态变量的值在内存中拥有固定的地址, 使用它的值总会访问到同样的数据
static APP_KEY: u32 = 111111;
static APP_SECRET: &str = "xxxxxxx";

#[derive(Debug, Deserialize)]
struct Resp {
    // 请求成功的字段
    access_token: Option<String>,
    aliId: Option<String>,
    refresh_token: Option<String>,
    resource_owner: Option<String>,
    expires_in: Option<String>,
    refresh_token_timeout: Option<String>,
    memberId: Option<String>,
    // 请求失败的字段
    error: Option<String>,
    error_description: Option<String>,
}

fn main() -> Result<(), reqwest::Error> {
    let url = format!("https://gw.open.1688.com/openapi/http/1/system.oauth2/getToken/{}?grant_type=authorization_code&need_refresh_token=true&client_id={}&client_secret={}&code={}",
                      APP_KEY,
                      APP_KEY,
                      APP_SECRET,
                      "7d0ee6a5-fc12-477a-b695-7fbd1a293c9a"); // 将临时code放入到这里

    let client = Client::new();
    let resp: Resp = client.post(url).send()?.json()?;

    println!("{:#?}", resp);

    Ok(())
}
